/*
Source : https://leetcode.com/problems/reverse-integer/
Author : nflush@outlook.com
Date   : 2016-05-11
*/
/*
24. Swap Nodes in Pairs  
Total Accepted: 97168 Total Submissions: 275204 Difficulty: Easy

Given a linked list, swap every two adjacent nodes and return its head.

For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.

Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.

Subscribe to see which companies asked this question
*/

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* swapPairs(struct ListNode* head) {
    struct ListNode* pH, *pN;
    int x = 1;
    pH = head;
    while(pH){
        if (x){
            pN = pH;
            x--;
        } else {
            pN->next = pH->next;
            pH->next = pN;
            x = 1;
        }
        pH = pN->next;
    }
    return head;
}

